package io.github.uicdb.badskill.block;

import io.github.uicdb.badskill.BSConfig;
import io.github.uicdb.badskill.PlayerSkillCapabilityProvider;
import io.github.uicdb.badskill.SkillOption;
import io.github.uicdb.badskill.SkillOptionManager;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.PressurePlateBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockSetType;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class OptionPressurePlate extends PressurePlateBlock {
    public OptionPressurePlate(Properties p_273571_) {
        super(Sensitivity.MOBS, p_273571_, BlockSetType.STONE);
    }

    @Override
    public void entityInside(BlockState p_49314_, Level p_49315_, BlockPos p_49316_, Entity entity) {
        if(entity instanceof Player player){
            var cap=player.getCapability(PlayerSkillCapabilityProvider.CAPABILITY);
            if(cap.isPresent()&&cap.resolve().isPresent()){
                if(BSConfig.PRESSURE_PLATE_REQUIRES.get().stream().anyMatch(r->cap.resolve().orElseThrow().isLearned(new ResourceLocation(r))))
                    super.entityInside(p_49314_, p_49315_, p_49316_, entity);
            }
        }
    }
    @Override
    public void appendHoverText(ItemStack p_49816_, @Nullable BlockGetter p_49817_, List<Component> components, TooltipFlag p_49819_) {
        super.appendHoverText(p_49816_, p_49817_, components, p_49819_);
        List<SkillOption> options=new ArrayList<>();
        for (String s : BSConfig.PRESSURE_PLATE_REQUIRES.get()) {
            SkillOption option= SkillOptionManager.INSTANCE.OPTIONS.get(new ResourceLocation(s));
            if(option!=null)
                options.add(option);
        }
        if(options.isEmpty()){
            components.add(Component.translatable("tip.option.not_find"));
        }else {
            components.add(Component.translatable("tip.option.require"));
            for (SkillOption option : options) {
                components.add(Component.translatable("tips.panel." + option.id.getNamespace() + "." + option.id.getPath() + ".title"));
            }
        }
    }
}
